$(function () {
    validateData();
    $('body').on('click','#submitUserMember',function () {
        saveUserMember();
    });
    $('body').on('click','#onBack',function () {
        onBackHistory();
    });
});

/**
 * 取消
 */
function onBackHistory() {
    window.history.go(-1);
}

/**
 * 验证正整数和小数
 */
function isDecimalAndInteger(str){
    var decimalAndInteger = /^[\d]+\.?[\d]{0,2}$/;
    if(decimalAndInteger.test(str)){
        return true;
    }
    return false;
}
/**
 * 提交方法
 */
function saveUserMember() {
        var userNumberPrice = $('input[name = "price"]').val();
        if(isDecimalAndInteger(userNumberPrice) == false){
            icModale(0,"请正确输入会员价格");
            return;
        }
    var validDay = $('input[name = "validDay"]').val();
    if(validDay>1000){
        icModale(0,"会员有效天数,不得大于1000天");
        return;
    }
        var params = $("#saveUserMemberFrom").serializeJSON();
        params = JSON.stringify(params);
        $.ajax({
            url:baseloaction+"/admin/user/cus/saveUpdateUserMember",
            data:params,
            type:"post",
            dataType:"json",
            contentType:'application/json;charset=utf-8',
            success:function (result) {
                if (result.success == true) {
                    icModale(0,result.message);
                    window.location.href=baseloaction+"/admin/user/cus/toUserMemberListPage"
                } else {
                    icModale(0,result.message);
                }
            }
        });
}



